const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('m_storage', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true,
      comment: 'autoid'
    },
    tenant_id: {
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: '租户id'
    },
    user_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '系统用户id'
    },
    key: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '键'
    },
    value: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '值'
    }
  }, {
    sequelize,
    tableName: 'm_storage',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: 'PRIMARY',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'id' }
        ]
      },
      {
        name: 'idx_tenant_id',
        using: 'BTREE',
        fields: [
          { name: 'tenant_id' }
        ]
      },
      {
        name: 'idx_user_id',
        using: 'BTREE',
        fields: [
          { name: 'user_id' }
        ]
      }
    ]
  });
};
